package com.atfusu.service.impl;

import com.atfusu.base.BaseDao;
import com.atfusu.base.impl.BaseServiceImpl;
import com.atfusu.bean.entity.Admin;
import com.atfusu.bean.entity.HouseBroker;
import com.atfusu.bean.entity.Role;
import com.atfusu.dao.AdminDao;
import com.atfusu.dao.RoleDao;
import com.atfusu.service.AdminService;
import com.atfusu.service.HouseBrokerService;
import com.atfusu.util.MD5;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Title:
 * Author: fusu
 * DateTime:  2022/11/26
 * Description:
 **/
@DubboService
public class AdminServiceImpl extends BaseServiceImpl<Admin> implements AdminService {

    @Autowired
    private AdminDao adminDao;

    @Autowired
    private RoleDao roleDao;

    //需要houseBrokerService来获取已有的全部经纪人id
    @DubboReference
    private HouseBrokerService houseBrokerService;


    /**
     * 获取相关dao层对象
     */
    @Override
    protected BaseDao<Admin> getEntityDao() {
        return adminDao;
    }

    @Override
    public List<Admin> findOtherAdminsByHouseId(Long houseId) {
        List<HouseBroker> houseBrokers = houseBrokerService.findListByHouseId(houseId);
        List<Long> adminIds = new ArrayList<>();
        //遍历拿到所有的经纪人id并放入集合内
        for (HouseBroker houseBroker : houseBrokers) {
            adminIds.add(houseBroker.getBrokerId());
        }
        List<Admin> otherAdmins = adminDao.findOtherAdmins(adminIds);
        return otherAdmins;
    }

    @Override
    public Admin getAdminByUsername(String username) {
        return adminDao.getAdminByUsername(username);
    }


}
